npm dependencies

graph <- jsonlite::fromJSON("https://ecomfe.github.io/echarts-examples/public/data/asset/data/npmdepgraph.min10.json")

graph$nodes$size <- scales::rescale(graph$nodes$size, to = c(1,20))

e_charts() %>% 
  e_graph_gl() %>% 
  e_graph_nodes(graph$nodes, label, x, size) %>% 
  e_graph_edges(graph$edges, sourceID, targetID)

Flights

library(dplyr)

# download
flights <- jsonlite::fromJSON("https://ecomfe.github.io/echarts-examples/public/data-gl/asset/data/flights.json")

# airports
airports <- as.data.frame(flights$airports)
names(airports) <- flights$airportsFields

airports <- airports %>% 
  select(name, longitude, latitude) %>% 
  tibble::rownames_to_column("ID") %>% 
  mutate(ID = as.integer(paste0(ID)))

# routes
routes <- as.data.frame(flights$routes)
names(routes) <- c("ID", "from", "to")

# airlines
airlines <- as.data.frame(flights$airlines) %>% 
  tibble::rownames_to_column("ID") %>% 
  mutate(ID = as.integer(paste(ID))) %>% 
  select(ID, airline = V1, country = V2)

# bind
data <- routes %>% 
  inner_join(airports, by = c("from" = "ID")) %>% 
  inner_join(airports, by = c("to" = "ID"), suffix = c(".start", ".end")) %>%
  inner_join(airlines, by = "ID") %>% 
  select(airline, longitude.start, latitude.start, longitude.end, latitude.end) 

# initialise plot  
data %>%
  group_by(airline) %>% 
  e_charts() %>% 
  e_globe(
    base_texture = ea_asset("world dark"),
    environment = ea_asset("starfield"),
    displacementScale = 0.1,
    displacementQuality = "high",
    shading = "realistic",
    realisticMaterial = list(
      roughness = .2,
      metalness = 0
    ),
    postEffect = list(
      enable = TRUE,
      depthOfField = list(
        enable = FALSE
      )
    ),
    temporalSuperSampling = list(
      enable = TRUE
    ),
    light = list(
      ambient = list(
        intensity = 1
      ),
      main = list(
        intensity = .1,
        shadow = FALSE
      )
    ),
    viewControl = list(autoRotate = FALSE)
  ) %>% 
  e_legend(
    selectedMode = "single", 
    left = "left",
    textStyle = list(color = "#fff"),
    orient = "vertical"
  ) %>% 
  e_lines_3d(
    longitude.start, latitude.start, longitude.end, latitude.end, 
    coord_system = "globe", 
    effect = list(
      show = TRUE,
      trailWidth = 2,
      trailLength = 0.15,
      trailOpacity = 1,
      trailColor = 'rgb(30, 30, 60)'
    ),
    lineStyle = list(opacity = 0.1, widh = 0.5, color = 'rgb(50, 50, 150)')
  )

Population

data <- jsonlite::fromJSON("http://gallery.echartsjs.com/asset/get/s/data-1491887968120-rJODPy9ae.json")

data <- as.data.frame(data) %>%
  magrittr::set_names(c("x", "y", "z")) %>% 
  filter(z > 0) %>% 
  mutate(z = sqrt(z))

data %>%
  e_charts(x) %>% 
  e_globe(
    base_texture = ea_asset("world topo"),
    environment = ea_asset("starfield"),
    displacementScale = 0.04,
    shading = "realistic",
    realisticMaterial = list(
      roughness = .9
    ),
    postEffect = list(
      enable = TRUE
    )
  ) %>% 
  e_legend(
    show = FALSE
  ) %>% 
  e_scatter_3d(
    y, z,
    coord_system = "globe",
    blendMode = "lighter",
    symbolSize = 2
  ) %>% 
  e_visual_map(
    show = FALSE,
    min = 0, max = 60,
    inRange = list(1, 10)
  )

Gapminder

library(purrr)

data("gapminder", package = "gapminder")

titles <- map(unique(gapminder$year), function(x){
  list(
    text = "Gapminder",
    subtext = x,
    left = "center"
  )
})

gapminder %>% 
  group_by(year) %>% 
  e_charts(gdpPercap, timeline = TRUE) %>% 
  e_scatter(lifeExp, pop, country) %>% 
  e_y_axis(min = 20, max = 85) %>% 
  e_x_axis(type = "log", min = 100, max = 100000) %>% 
  e_timeline_serie(title = titles) %>% 
  e_tooltip() %>% 
  e_timeline_opts(
    show = TRUE,
    orient = "vertical",
    symbol = "none",
    right = 0,
    top = 20,
    bottom = 20,
    height = NULL,
    width = 45,
    inverse = TRUE,
    playInterval = 1000,
    autoPlay  = TRUE,
    controlStyle = list(
      showNextBtn = FALSE,
      showPrevBtn = FALSE
    ),
    label = list(
      fontSize = 8
    )
  ) %>% 
  e_theme("dark")


Buy me a coffeeBuy me a coffee

Site built with pkgdown